ABAP Select data from SAP table IFIORDAPTCOST 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 IFIORDAPTCOST 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 IFIORDAPTCOST. 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 IFIORDAPTCOST 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_IFIORDAPTCOST TYPE STANDARD TABLE OF IFIORDAPTCOST, WA_IFIORDAPTCOST TYPE IFIORDAPTCOST, 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: <IFIORDAPTCOST> TYPE IFIORDAPTCOST. *Process all fields in table header/work area as string values PERFORM process_as_string_field_values CHANGING wa_IFIORDAPTCOST. SELECT * *restrict ABAP select to first 10 rows UP TO 10 ROWS FROM IFIORDAPTCOST INTO TABLE IT_IFIORDAPTCOST. *Select data and declare internal table using in-line method @DATA *SELECT * * FROM IFIORDAPTCOST * INTO TABLE @DATA(IT_IFIORDAPTCOST2). *--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_IFIORDAPTCOST INDEX 1 INTO DATA(WA_IFIORDAPTCOST2). *Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL LOOP AT IT_IFIORDAPTCOST ASSIGNING <IFIORDAPTCOST>.*To update a field value using a field symbol simply change the value via the field symbol pointer
<IFIORDAPTCOST>-MANDT = 1.
<IFIORDAPTCOST>-LEDGER = 1.
<IFIORDAPTCOST>-ORDERID = 1.
<IFIORDAPTCOST>-WORKCENTERINTERNALID = 1.
<IFIORDAPTCOST>-WORKCENTER = 1.
ENDLOOP. LOOP AT IT_IFIORDAPTCOST INTO WA_IFIORDAPTCOST. *Write horizonal line to screen report. WRITE:/ sy-uline. *Write selected data to screen/report before conversion. WRITE:/ sy-vline, WA_IFIORDAPTCOST-ORDEROPERATION, sy-vline,
WA_IFIORDAPTCOST-GLACCOUNT, sy-vline,
WA_IFIORDAPTCOST-PARTNERCOSTCTRACTIVITYTYPE, sy-vline,
WA_IFIORDAPTCOST-PARTNERCOSTCENTER, sy-vline,
WA_IFIORDAPTCOST-PLANT, sy-vline,
WA_IFIORDAPTCOST-PRODUCT, sy-vline.
ENDLOOP. *Add any further fields from structure WA_IFIORDAPTCOST 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_IFIORDAPTCOST 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_IFIORDAPTCOST INTO WA_IFIORDAPTCOST. *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 ALPHA, internal->external for field LEDGER CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_IFIORDAPTCOST-LEDGER IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_IFIORDAPTCOST-LEDGER.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field ORDERID CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_IFIORDAPTCOST-ORDERID IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_IFIORDAPTCOST-ORDERID.
WRITE:/ 'New Value:', ld_input.
*Conversion exit NUMCV, internal->external for field ORDEROPERATION CALL FUNCTION 'CONVERSION_EXIT_NUMCV_OUTPUT' EXPORTING input = WA_IFIORDAPTCOST-ORDEROPERATION IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_IFIORDAPTCOST-ORDEROPERATION.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field GLACCOUNT CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_IFIORDAPTCOST-GLACCOUNT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_IFIORDAPTCOST-GLACCOUNT.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field PARTNERCOSTCENTER CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_IFIORDAPTCOST-PARTNERCOSTCENTER IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_IFIORDAPTCOST-PARTNERCOSTCENTER.
WRITE:/ 'New Value:', ld_input.
*Conversion exit MATN1, internal->external for field PRODUCT CALL FUNCTION 'CONVERSION_EXIT_MATN1_OUTPUT' EXPORTING input = WA_IFIORDAPTCOST-PRODUCT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_IFIORDAPTCOST-PRODUCT.
WRITE:/ 'New Value:', ld_input.
*Conversion exit CUNIT, internal->external for field UNITOFMEASURE CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_IFIORDAPTCOST-UNITOFMEASURE IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_IFIORDAPTCOST-UNITOFMEASURE.
WRITE:/ 'New Value:', ld_input.
*Conversion exit MATN1, internal->external for field PRODUCEDPRODUCT CALL FUNCTION 'CONVERSION_EXIT_MATN1_OUTPUT' EXPORTING input = WA_IFIORDAPTCOST-PRODUCEDPRODUCT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_IFIORDAPTCOST-PRODUCEDPRODUCT.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field SALESORDER CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_IFIORDAPTCOST-SALESORDER IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_IFIORDAPTCOST-SALESORDER.
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_IFIORDAPTCOST_STR,
MANDT TYPE STRING,
LEDGER TYPE STRING,
ORDERID TYPE STRING,
WORKCENTERINTERNALID TYPE STRING,
WORKCENTER TYPE STRING,
ORDEROPERATION TYPE STRING,
GLACCOUNT TYPE STRING,
PARTNERCOSTCTRACTIVITYTYPE TYPE STRING,
PARTNERCOSTCENTER TYPE STRING,
PLANT TYPE STRING,
PRODUCT TYPE STRING,
UNITOFMEASURE TYPE STRING,
CONTROLLINGAREA TYPE STRING,
COMPANYCODE TYPE STRING,
PRODUCEDPRODUCT TYPE STRING,
CHARTOFACCOUNTS TYPE STRING,
SALESORDER TYPE STRING,
SALESORDERITEM TYPE STRING,
ORDERTYPE TYPE STRING,
ORDERCATEGORY TYPE STRING,
DISPLAYCURRENCY TYPE STRING,
CREDITACTLCOSTINDSPCRCY TYPE STRING,
DEBITACTLCOSTINDSPCRCY TYPE STRING,
CRDTACTLFXDCOSTINDSPCRCY TYPE STRING,
DEBITACTLFXDCOSTINDSPCRCY TYPE STRING,
ACTUALQTYINCOSTSOURCEUNIT TYPE STRING,
CREDITPLANCOSTINDSPCRCY TYPE STRING,
DEBITPLANCOSTINDSPCRCY TYPE STRING,
CRDTPLNFXDCOSTINDSPCRCY TYPE STRING,
DEBITPLNFXDCOSTINDSPCRCY TYPE STRING,
PLANQTYINCOSTSOURCEUNIT TYPE STRING,
CRDTTARGETCOSTINDSPCRCY TYPE STRING,
DEBITTARGETCOSTINDSPCRCY TYPE STRING,END OF T_EKKO_STR. DATA: WA_IFIORDAPTCOST_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_IFIORDAPTCOST_STR-MANDT sy-vline
WA_IFIORDAPTCOST_STR-LEDGER sy-vline
WA_IFIORDAPTCOST_STR-ORDERID sy-vline
WA_IFIORDAPTCOST_STR-WORKCENTERINTERNALID sy-vline
WA_IFIORDAPTCOST_STR-WORKCENTER sy-vline
WA_IFIORDAPTCOST_STR-ORDEROPERATION sy-vline
WA_IFIORDAPTCOST_STR-GLACCOUNT sy-vline
WA_IFIORDAPTCOST_STR-PARTNERCOSTCTRACTIVITYTYPE sy-vline
WA_IFIORDAPTCOST_STR-PARTNERCOSTCENTER sy-vline
WA_IFIORDAPTCOST_STR-PLANT sy-vline
WA_IFIORDAPTCOST_STR-PRODUCT sy-vline
WA_IFIORDAPTCOST_STR-UNITOFMEASURE sy-vline
WA_IFIORDAPTCOST_STR-CONTROLLINGAREA sy-vline
WA_IFIORDAPTCOST_STR-COMPANYCODE sy-vline
WA_IFIORDAPTCOST_STR-PRODUCEDPRODUCT sy-vline
WA_IFIORDAPTCOST_STR-CHARTOFACCOUNTS sy-vline
WA_IFIORDAPTCOST_STR-SALESORDER sy-vline
WA_IFIORDAPTCOST_STR-SALESORDERITEM sy-vline
WA_IFIORDAPTCOST_STR-ORDERTYPE sy-vline
WA_IFIORDAPTCOST_STR-ORDERCATEGORY sy-vline
WA_IFIORDAPTCOST_STR-DISPLAYCURRENCY sy-vline
WA_IFIORDAPTCOST_STR-CREDITACTLCOSTINDSPCRCY sy-vline
WA_IFIORDAPTCOST_STR-DEBITACTLCOSTINDSPCRCY sy-vline
WA_IFIORDAPTCOST_STR-CRDTACTLFXDCOSTINDSPCRCY sy-vline
WA_IFIORDAPTCOST_STR-DEBITACTLFXDCOSTINDSPCRCY sy-vline
WA_IFIORDAPTCOST_STR-ACTUALQTYINCOSTSOURCEUNIT sy-vline
WA_IFIORDAPTCOST_STR-CREDITPLANCOSTINDSPCRCY sy-vline
WA_IFIORDAPTCOST_STR-DEBITPLANCOSTINDSPCRCY sy-vline
WA_IFIORDAPTCOST_STR-CRDTPLNFXDCOSTINDSPCRCY sy-vline
WA_IFIORDAPTCOST_STR-DEBITPLNFXDCOSTINDSPCRCY sy-vline
WA_IFIORDAPTCOST_STR-PLANQTYINCOSTSOURCEUNIT sy-vline
WA_IFIORDAPTCOST_STR-CRDTTARGETCOSTINDSPCRCY sy-vline
WA_IFIORDAPTCOST_STR-DEBITTARGETCOSTINDSPCRCY sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.