Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

reading data from table control in an internal table

Former Member
0 Kudos

Hello All,

I want to read the data entered in the screen in an internal table,screen has header segment fields of an idoc and two item segment fields with multiple occurance in form of two table control,have to read both the table control and have to pass it to idoc inbound function based on postion(posnr) of the order. can anyone provide me with the sample code for the same .

Thanks and Regards,

Gunjan

1 ACCEPTED SOLUTION

Former Member
0 Kudos

hi gunjan

refer to the folllowing code. it will work for u



Creation of an IDoc generation program
The following code extract contains everything needed to generate an IDoc from data contained in a table.
FORM F_110_SEND_IDOC.
CONSTANTS:
  C_MESTYP TYPE EDIDC-MESTYP VALUE 'ZVISTAPM',"message type
  C_DOCTYP TYPE EDIDC-IDOCTP VALUE 'ZVISTAPM01',"idoc type
  C_SEGNAM TYPE EDIDD-SEGNAM VALUE 'Z1VISTAPM'."segment name
DATA:
  I_ZVISTA_PM TYPE ZVISTA_PM_T OCCURS 6000,
  I_EDIDC TYPE EDIDC OCCURS 0,
  I_EDIDD TYPE EDIDD OCCURS 0,
  WA_ZVISTA_PM TYPE ZVISTA_PM_T,
  WA_EDIDC TYPE EDIDC,
  WA_EDIDD TYPE EDIDD,
  WA_Z1VISTAPM TYPE Z1VISTAPM,
  V_OCCMAX TYPE IDOCSYN-OCCMAX,
  V_NBSEG TYPE I.
CLEAR WA_ZVISTA_PM.
CLEAR WA_EDIDC.
* Save the message type and the basic IDoc type
* in the control segment
MOVE C_MESTYP TO WA_EDIDC-MESTYP.
MOVE C_DOCTYP TO WA_EDIDC-IDOCTP.
* Retrieve the maximum number of segments in the basic IDoc
* type
SELECT MIN( OCCMAX )
  FROM IDOCSYN
  INTO V_OCCMAX
  WHERE IDOCTYP EQ C_DOCTYP AND SEGTYP EQ C_SEGNAM.
* Save the whole ZVISTA_PM_T table content
* in the I_ZVISTA_PM internal table.
SELECT *
FROM ZVISTA_PM_T
INTO CORRESPONDING FIELDS OF TABLE I_ZVISTA_PM.
* Create a data segment for each line of I_ZVISTA_PM
LOOP AT I_ZVISTA_PM INTO WA_ZVISTA_PM.
  MOVE-CORRESPONDING WA_ZVISTA_PM TO WA_Z1VISTAPM.
  CLEAR WA_EDIDD.
  MOVE C_SEGNAM TO WA_EDIDD-SEGNAM.
  MOVE WA_Z1VISTAPM TO WA_EDIDD-SDATA.
  APPEND WA_EDIDD TO I_EDIDD.
  CLEAR WA_ZVISTA_PM.
  CLEAR WA_Z1VISTAPM.
ENDLOOP.
* Count the number of data segments
DESCRIBE TABLE I_EDIDD LINES V_NBSEG.
* If the number of data segments exceeds the maximum
* allowed number, then edit a message in the spool,
* then display an error message (quit the program)
IF V_NBSEG GT V_OCCMAX.
  WRITE:/ TEXT-003, V_OCCMAX.
  MESSAGE E751.
ENDIF.
* Call the IDoc creation function
CALL FUNCTION 'MASTER_IDOC_DISTRIBUTE'
  EXPORTING
    MASTER_IDOC_CONTROL = WA_EDIDC
  TABLES
    COMMUNICATION_IDOC_CONTROL = I_EDIDC
    MASTER_IDOC_DATA = I_EDIDD
  EXCEPTIONS
    ERROR_IN_IDOC_CONTROL = 1
    ERROR_WRITING_IDOC_STATUS = 2
    ERROR_IN_IDOC_DATA = 3
    SENDING_LOGICAL_SYSTEM_UNKNOWN = 4
    OTHERS = 5.
* If there was an error, display a message (quit the
* program)
IF SY-SUBRC NE 0.
  MESSAGE E746.
ENDIF.
ENDFORM.

regards

ravish

<b>plz dont forget to reward points if useful</b>

3 REPLIES 3

Former Member
0 Kudos

hi gunjan

refer to the folllowing code. it will work for u



Creation of an IDoc generation program
The following code extract contains everything needed to generate an IDoc from data contained in a table.
FORM F_110_SEND_IDOC.
CONSTANTS:
  C_MESTYP TYPE EDIDC-MESTYP VALUE 'ZVISTAPM',"message type
  C_DOCTYP TYPE EDIDC-IDOCTP VALUE 'ZVISTAPM01',"idoc type
  C_SEGNAM TYPE EDIDD-SEGNAM VALUE 'Z1VISTAPM'."segment name
DATA:
  I_ZVISTA_PM TYPE ZVISTA_PM_T OCCURS 6000,
  I_EDIDC TYPE EDIDC OCCURS 0,
  I_EDIDD TYPE EDIDD OCCURS 0,
  WA_ZVISTA_PM TYPE ZVISTA_PM_T,
  WA_EDIDC TYPE EDIDC,
  WA_EDIDD TYPE EDIDD,
  WA_Z1VISTAPM TYPE Z1VISTAPM,
  V_OCCMAX TYPE IDOCSYN-OCCMAX,
  V_NBSEG TYPE I.
CLEAR WA_ZVISTA_PM.
CLEAR WA_EDIDC.
* Save the message type and the basic IDoc type
* in the control segment
MOVE C_MESTYP TO WA_EDIDC-MESTYP.
MOVE C_DOCTYP TO WA_EDIDC-IDOCTP.
* Retrieve the maximum number of segments in the basic IDoc
* type
SELECT MIN( OCCMAX )
  FROM IDOCSYN
  INTO V_OCCMAX
  WHERE IDOCTYP EQ C_DOCTYP AND SEGTYP EQ C_SEGNAM.
* Save the whole ZVISTA_PM_T table content
* in the I_ZVISTA_PM internal table.
SELECT *
FROM ZVISTA_PM_T
INTO CORRESPONDING FIELDS OF TABLE I_ZVISTA_PM.
* Create a data segment for each line of I_ZVISTA_PM
LOOP AT I_ZVISTA_PM INTO WA_ZVISTA_PM.
  MOVE-CORRESPONDING WA_ZVISTA_PM TO WA_Z1VISTAPM.
  CLEAR WA_EDIDD.
  MOVE C_SEGNAM TO WA_EDIDD-SEGNAM.
  MOVE WA_Z1VISTAPM TO WA_EDIDD-SDATA.
  APPEND WA_EDIDD TO I_EDIDD.
  CLEAR WA_ZVISTA_PM.
  CLEAR WA_Z1VISTAPM.
ENDLOOP.
* Count the number of data segments
DESCRIBE TABLE I_EDIDD LINES V_NBSEG.
* If the number of data segments exceeds the maximum
* allowed number, then edit a message in the spool,
* then display an error message (quit the program)
IF V_NBSEG GT V_OCCMAX.
  WRITE:/ TEXT-003, V_OCCMAX.
  MESSAGE E751.
ENDIF.
* Call the IDoc creation function
CALL FUNCTION 'MASTER_IDOC_DISTRIBUTE'
  EXPORTING
    MASTER_IDOC_CONTROL = WA_EDIDC
  TABLES
    COMMUNICATION_IDOC_CONTROL = I_EDIDC
    MASTER_IDOC_DATA = I_EDIDD
  EXCEPTIONS
    ERROR_IN_IDOC_CONTROL = 1
    ERROR_WRITING_IDOC_STATUS = 2
    ERROR_IN_IDOC_DATA = 3
    SENDING_LOGICAL_SYSTEM_UNKNOWN = 4
    OTHERS = 5.
* If there was an error, display a message (quit the
* program)
IF SY-SUBRC NE 0.
  MESSAGE E746.
ENDIF.
ENDFORM.

regards

ravish

<b>plz dont forget to reward points if useful</b>

0 Kudos

Hello ravish,

thanks for the code.

but i need to do it with table control, that is the segment data in table control will be transfered to edidd. using parameters i could do it. but i have to make amodule pool for the same.

Regards,

Gunjan

Former Member
0 Kudos

hi gunjan

is it like u have the segment data in the table control ??

regards

ravish