ABAP Select data from SAP table IDFSALLWNCPLHN into internal table
Get Example source ABAP code based on a different SAP table
Below is a number of ABAP code snippets to demonstrate how to select data from SAP IDFSALLWNCPLHN table and store it within an internal table, including using the newer @DATA inline declaration methods. It also shows you various ways to process this data using ABAP work area, inline declaration or field symbols including executing all the relevant CONVERSION_EXIT routines specific to IDFSALLWNCPLHN. See here for more generic Select statement tips.
Sometimes data within SAP is stored within the database table in a different format to what it is displayed to the user. These input/output conversation FM routines are what translates the data between the two formats.
There is also a full declaration of the IDFSALLWNCPLHN table where each field has a char/string type for you to simply copy and paste. This allows you to use processing that is only available to these field types such as the CONCATENATE statement.
DATA: IT_IDFSALLWNCPLHN TYPE STANDARD TABLE OF IDFSALLWNCPLHN, WA_IDFSALLWNCPLHN TYPE IDFSALLWNCPLHN, GD_STR TYPE STRING. DATA: lo_typedescr type REF TO cl_abap_typedescr. DATA: lv_fieldname type fieldname. FIELD-SYMBOLS: <FIELD> TYPE any. FIELD-SYMBOLS: <IDFSALLWNCPLHN> TYPE IDFSALLWNCPLHN. *Process all fields in table header/work area as string values PERFORM process_as_string_field_values CHANGING wa_IDFSALLWNCPLHN. SELECT * *restrict ABAP select to first 10 rows UP TO 10 ROWS FROM IDFSALLWNCPLHN INTO TABLE IT_IDFSALLWNCPLHN. *Select data and declare internal table using in-line method @DATA *SELECT * * FROM IDFSALLWNCPLHN * INTO TABLE @DATA(IT_IDFSALLWNCPLHN2). *--Further methods of using ABAP code to select data from SAP database tables *You can also declare the header/work area using the in-line DATA declaration method READ TABLE IT_IDFSALLWNCPLHN INDEX 1 INTO DATA(WA_IDFSALLWNCPLHN2). *Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL LOOP AT IT_IDFSALLWNCPLHN ASSIGNING <IDFSALLWNCPLHN>.*To update a field value using a field symbol simply change the value via the field symbol pointer
<IDFSALLWNCPLHN>-MANDT = 1.
<IDFSALLWNCPLHN>-DFSALLWNCPLANUUID = 1.
<IDFSALLWNCPLHN>-DFSALLWNCPLANHIERID = 1.
<IDFSALLWNCPLHN>-DFSALLWNCPLANPREVIOUSPLNHIERID = 1.
<IDFSALLWNCPLHN>-LANGUAGE = 1.
ENDLOOP. LOOP AT IT_IDFSALLWNCPLHN INTO WA_IDFSALLWNCPLHN. *Write horizonal line to screen report. WRITE:/ sy-uline. *Write selected data to screen/report before conversion. WRITE:/ sy-vline, WA_IDFSALLWNCPLHN-DFSALLWNCPLANID, sy-vline,
WA_IDFSALLWNCPLHN-DFSALLWNCPLANDESCRIPTION, sy-vline,
WA_IDFSALLWNCPLHN-DFSALLWNCPLANVALDTYSTRTDATE, sy-vline,
WA_IDFSALLWNCPLHN-DFSALLWNCPLANVALDTYENDDATE, sy-vline,
WA_IDFSALLWNCPLHN-FLXBLMATLPLNGOBJECTUUID, sy-vline,
WA_IDFSALLWNCPLHN-FLXBLMATLPLNGOBJECTID, sy-vline.
ENDLOOP. *Add any further fields from structure WA_IDFSALLWNCPLHN you want to display... WRITE:/ sy-uline. * Aternatively use generic code to Write field values (and NAME) to screen report DO. ASSIGN COMPONENT sy-index OF STRUCTURE wa_IDFSALLWNCPLHN TO <field>. IF sy-subrc <> 0. EXIT. ENDIF. WRITE:/ 'Field Value', <field>, sy-vline. gd_str = <field> . lo_typedescr ?= CL_ABAP_DATADESCR=>DESCRIBE_BY_DATA( <field> ). lv_fieldname = lo_typedescr->GET_RELATIVE_NAME( ). WRITE:/ 'Field Name', lv_fieldname. ENDDO. *Redo loop but convert all fields from internal to out value LOOP AT IT_IDFSALLWNCPLHN INTO WA_IDFSALLWNCPLHN. *Write horizonal line to screen report. WRITE:/ sy-uline. *Convert all fields to display/output versions using conversion routines PERFORM convert_all_field_values CHANGING wa_EKKO. ENDLOOP. *&---------------------------------------------------------------------* *& Form convert_all_field_values *&---------------------------------------------------------------------* FORM convert_all_field_values CHANGING p_EKKO LIKE wa_EKKO. DATA: ld_input(1000) TYPE c, ld_output(1000) TYPE C.
*Conversion exit MATN1, internal->external for field PRODUCT CALL FUNCTION 'CONVERSION_EXIT_MATN1_OUTPUT' EXPORTING input = WA_IDFSALLWNCPLHN-PRODUCT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_IDFSALLWNCPLHN-PRODUCT.
WRITE:/ 'New Value:', ld_input.
*Conversion exit CUNIT, internal->external for field DFSALLWNCPLANQUANTITYUNIT CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_IDFSALLWNCPLHN-DFSALLWNCPLANQUANTITYUNIT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_IDFSALLWNCPLHN-DFSALLWNCPLANQUANTITYUNIT.
WRITE:/ 'New Value:', ld_input.
ENDFORM. *&---------------------------------------------------------------------* *& Form process_as_string_field_values *&---------------------------------------------------------------------* FORM process_as_string_field_values CHANGING p_EKKO LIKE wa_EKKO. TYPES: BEGIN OF T_IDFSALLWNCPLHN_STR,
MANDT TYPE STRING,
DFSALLWNCPLANUUID TYPE STRING,
DFSALLWNCPLANHIERID TYPE STRING,
DFSALLWNCPLANPREVIOUSPLNHIERID TYPE STRING,
LANGUAGE TYPE STRING,
DFSALLWNCPLANID TYPE STRING,
DFSALLWNCPLANDESCRIPTION TYPE STRING,
DFSALLWNCPLANVALDTYSTRTDATE TYPE STRING,
DFSALLWNCPLANVALDTYENDDATE TYPE STRING,
FLXBLMATLPLNGOBJECTUUID TYPE STRING,
FLXBLMATLPLNGOBJECTID TYPE STRING,
FLXBLMATLPLNGOBJVARIANTUUID TYPE STRING,
FLXBLMATLPLNGOBJVARIANTID TYPE STRING,
PRODUCT TYPE STRING,
DFSALLWNCPLANBASETYPE TYPE STRING,
DFSALLWNCPLANALLOWEDQUANTITY TYPE STRING,
DFSALLWNCPLANQUANTITYUNIT TYPE STRING,
FRCELMNTORGUSAGETYPE TYPE STRING,
DFSALLWNCPLANMULTILEVEL TYPE STRING,
DFSALLWNCPLANPREVIOUSPLANUUID TYPE STRING,
DFSALLWNCPLANCOMMENT TYPE STRING,
FORCEELEMENTORGUUID TYPE STRING,
FORCEELEMENTORGID TYPE STRING,
DFSALLWNCPLANISCOMPLETED TYPE STRING,
DFSALLWNCPLANSTATUSOBJECT TYPE STRING,
DFSALLWNCPLANSTATUSCODE TYPE STRING,
DFSALLWNCPLANSTATUSPROFILE TYPE STRING,
PRODUCTNAME TYPE STRING,
DFSALLWNCPLANUSEDQUANTITY TYPE STRING,
STATUSCRITICALITY TYPE STRING,
STATUS TYPE STRING,
DFSALLWNCPLANPREVIOUSPLANID TYPE STRING,
FLXBLMATLPLNGOBJDESCRIPTION TYPE STRING,
FLXBLMATLPLNGOBJVARIANTDESC TYPE STRING,
FRCELMNTORGUSAGETYPEDESC TYPE STRING,
DFSALLWNCPLANBASETYPEDESC TYPE STRING,
DFSALLWNCPLANMULTILEVELDESC TYPE STRING,
DFSALLWNCPLANISFUPHIDDEN TYPE STRING,
DFSALLWNCPLANISREQHIDDEN TYPE STRING,
FRCELMNTORGNAME TYPE STRING,
DFSALLWNCPLANCOMPLETEDSTATUS TYPE STRING,
DFSALLWNCREQID TYPE STRING,
DFSALLWNCREQUUID TYPE STRING,
DFSALLWNCPLANCREATIONDATETIME TYPE STRING,
DFSALLWNCPLANCREATEDBYUSER TYPE STRING,
DFSALLWNCPLANCHANGEDATETIME TYPE STRING,
DFSALLWNCPLANLASTCHGDBYUSER TYPE STRING,
DFSPLANISROOT TYPE STRING,END OF T_EKKO_STR. DATA: WA_IDFSALLWNCPLHN_STR type T_EKKO_STR. DATA: ld_text TYPE string. LOOP AT IT_EKKO INTO WA_EKKO. MOVE-CORRESPONDING wa_EKKO TO WA_EKKO_STR. CONCATENATE: sy-vline
WA_IDFSALLWNCPLHN_STR-MANDT sy-vline
WA_IDFSALLWNCPLHN_STR-DFSALLWNCPLANUUID sy-vline
WA_IDFSALLWNCPLHN_STR-DFSALLWNCPLANHIERID sy-vline
WA_IDFSALLWNCPLHN_STR-DFSALLWNCPLANPREVIOUSPLNHIERID sy-vline
WA_IDFSALLWNCPLHN_STR-LANGUAGE sy-vline
WA_IDFSALLWNCPLHN_STR-DFSALLWNCPLANID sy-vline
WA_IDFSALLWNCPLHN_STR-DFSALLWNCPLANDESCRIPTION sy-vline
WA_IDFSALLWNCPLHN_STR-DFSALLWNCPLANVALDTYSTRTDATE sy-vline
WA_IDFSALLWNCPLHN_STR-DFSALLWNCPLANVALDTYENDDATE sy-vline
WA_IDFSALLWNCPLHN_STR-FLXBLMATLPLNGOBJECTUUID sy-vline
WA_IDFSALLWNCPLHN_STR-FLXBLMATLPLNGOBJECTID sy-vline
WA_IDFSALLWNCPLHN_STR-FLXBLMATLPLNGOBJVARIANTUUID sy-vline
WA_IDFSALLWNCPLHN_STR-FLXBLMATLPLNGOBJVARIANTID sy-vline
WA_IDFSALLWNCPLHN_STR-PRODUCT sy-vline
WA_IDFSALLWNCPLHN_STR-DFSALLWNCPLANBASETYPE sy-vline
WA_IDFSALLWNCPLHN_STR-DFSALLWNCPLANALLOWEDQUANTITY sy-vline
WA_IDFSALLWNCPLHN_STR-DFSALLWNCPLANQUANTITYUNIT sy-vline
WA_IDFSALLWNCPLHN_STR-FRCELMNTORGUSAGETYPE sy-vline
WA_IDFSALLWNCPLHN_STR-DFSALLWNCPLANMULTILEVEL sy-vline
WA_IDFSALLWNCPLHN_STR-DFSALLWNCPLANPREVIOUSPLANUUID sy-vline
WA_IDFSALLWNCPLHN_STR-DFSALLWNCPLANCOMMENT sy-vline
WA_IDFSALLWNCPLHN_STR-FORCEELEMENTORGUUID sy-vline
WA_IDFSALLWNCPLHN_STR-FORCEELEMENTORGID sy-vline
WA_IDFSALLWNCPLHN_STR-DFSALLWNCPLANISCOMPLETED sy-vline
WA_IDFSALLWNCPLHN_STR-DFSALLWNCPLANSTATUSOBJECT sy-vline
WA_IDFSALLWNCPLHN_STR-DFSALLWNCPLANSTATUSCODE sy-vline
WA_IDFSALLWNCPLHN_STR-DFSALLWNCPLANSTATUSPROFILE sy-vline
WA_IDFSALLWNCPLHN_STR-PRODUCTNAME sy-vline
WA_IDFSALLWNCPLHN_STR-DFSALLWNCPLANUSEDQUANTITY sy-vline
WA_IDFSALLWNCPLHN_STR-STATUSCRITICALITY sy-vline
WA_IDFSALLWNCPLHN_STR-STATUS sy-vline
WA_IDFSALLWNCPLHN_STR-DFSALLWNCPLANPREVIOUSPLANID sy-vline
WA_IDFSALLWNCPLHN_STR-FLXBLMATLPLNGOBJDESCRIPTION sy-vline
WA_IDFSALLWNCPLHN_STR-FLXBLMATLPLNGOBJVARIANTDESC sy-vline
WA_IDFSALLWNCPLHN_STR-FRCELMNTORGUSAGETYPEDESC sy-vline
WA_IDFSALLWNCPLHN_STR-DFSALLWNCPLANBASETYPEDESC sy-vline
WA_IDFSALLWNCPLHN_STR-DFSALLWNCPLANMULTILEVELDESC sy-vline
WA_IDFSALLWNCPLHN_STR-DFSALLWNCPLANISFUPHIDDEN sy-vline
WA_IDFSALLWNCPLHN_STR-DFSALLWNCPLANISREQHIDDEN sy-vline
WA_IDFSALLWNCPLHN_STR-FRCELMNTORGNAME sy-vline
WA_IDFSALLWNCPLHN_STR-DFSALLWNCPLANCOMPLETEDSTATUS sy-vline
WA_IDFSALLWNCPLHN_STR-DFSALLWNCREQID sy-vline
WA_IDFSALLWNCPLHN_STR-DFSALLWNCREQUUID sy-vline
WA_IDFSALLWNCPLHN_STR-DFSALLWNCPLANCREATIONDATETIME sy-vline
WA_IDFSALLWNCPLHN_STR-DFSALLWNCPLANCREATEDBYUSER sy-vline
WA_IDFSALLWNCPLHN_STR-DFSALLWNCPLANCHANGEDATETIME sy-vline
WA_IDFSALLWNCPLHN_STR-DFSALLWNCPLANLASTCHGDBYUSER sy-vline
WA_IDFSALLWNCPLHN_STR-DFSPLANISROOT sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.