ABAP Select data from SAP table PDGRKONVDJDEND 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 PDGRKONVDJDEND 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 PDGRKONVDJDEND. 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 PDGRKONVDJDEND 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_PDGRKONVDJDEND TYPE STANDARD TABLE OF PDGRKONVDJDEND, WA_PDGRKONVDJDEND TYPE PDGRKONVDJDEND, 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: <PDGRKONVDJDEND> TYPE PDGRKONVDJDEND. *Process all fields in table header/work area as string values PERFORM process_as_string_field_values CHANGING wa_PDGRKONVDJDEND. SELECT * *restrict ABAP select to first 10 rows UP TO 10 ROWS FROM PDGRKONVDJDEND INTO TABLE IT_PDGRKONVDJDEND. *Select data and declare internal table using in-line method @DATA *SELECT * * FROM PDGRKONVDJDEND * INTO TABLE @DATA(IT_PDGRKONVDJDEND2). *--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_PDGRKONVDJDEND INDEX 1 INTO DATA(WA_PDGRKONVDJDEND2). *Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL LOOP AT IT_PDGRKONVDJDEND ASSIGNING <PDGRKONVDJDEND>.*To update a field value using a field symbol simply change the value via the field symbol pointer
<PDGRKONVDJDEND>-MANDT = 1.
<PDGRKONVDJDEND>-PRICINGKEY = 1.
<PDGRKONVDJDEND>-PRICINGDOCUMENTITEM = 1.
<PDGRKONVDJDEND>-CONDITIONTYPE = 1.
<PDGRKONVDJDEND>-SUBCONDITIONTYPE = 1.
ENDLOOP. LOOP AT IT_PDGRKONVDJDEND INTO WA_PDGRKONVDJDEND. *Write horizonal line to screen report. WRITE:/ sy-uline. *Write selected data to screen/report before conversion. WRITE:/ sy-vline, WA_PDGRKONVDJDEND-VERSSTOCKRECORDUUID, sy-vline,
WA_PDGRKONVDJDEND-MTMDATASOURCETYPE, sy-vline,
WA_PDGRKONVDJDEND-SOURCETRANSACTIONEVENTDATETIME, sy-vline,
WA_PDGRKONVDJDEND-SOURCETRANSACEVENTENDDATETIME, sy-vline,
WA_PDGRKONVDJDEND-SOURCETRANSACTIONEVENTDATE, sy-vline,
WA_PDGRKONVDJDEND-MATERIALBASEUNIT, sy-vline.
ENDLOOP. *Add any further fields from structure WA_PDGRKONVDJDEND 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_PDGRKONVDJDEND 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_PDGRKONVDJDEND INTO WA_PDGRKONVDJDEND. *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 CUNIT, internal->external for field MATERIALBASEUNIT CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_PDGRKONVDJDEND-MATERIALBASEUNIT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_PDGRKONVDJDEND-MATERIALBASEUNIT.
WRITE:/ 'New Value:', ld_input.
*Conversion exit CUNIT, internal->external for field COMMODITYUNIT CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_PDGRKONVDJDEND-COMMODITYUNIT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_PDGRKONVDJDEND-COMMODITYUNIT.
WRITE:/ 'New Value:', ld_input.
*Conversion exit CUNIT, internal->external for field CMMDTYPRICEEXPSRMASSUNIT CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_PDGRKONVDJDEND-CMMDTYPRICEEXPSRMASSUNIT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_PDGRKONVDJDEND-CMMDTYPRICEEXPSRMASSUNIT.
WRITE:/ 'New Value:', ld_input.
*Conversion exit CUNIT, internal->external for field CMMDTYPRICEEXPSRVOLUMEUNIT CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_PDGRKONVDJDEND-CMMDTYPRICEEXPSRVOLUMEUNIT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_PDGRKONVDJDEND-CMMDTYPRICEEXPSRVOLUMEUNIT.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field SOURCEDOCUMENT CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_PDGRKONVDJDEND-SOURCEDOCUMENT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_PDGRKONVDJDEND-SOURCEDOCUMENT.
WRITE:/ 'New Value:', ld_input.
*Conversion exit GJAHR, internal->external for field SOURCEDOCUMENTYEAR CALL FUNCTION 'CONVERSION_EXIT_GJAHR_OUTPUT' EXPORTING input = WA_PDGRKONVDJDEND-SOURCEDOCUMENTYEAR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_PDGRKONVDJDEND-SOURCEDOCUMENTYEAR.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field LOADDATACAPTUREOBJECTID CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_PDGRKONVDJDEND-LOADDATACAPTUREOBJECTID IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_PDGRKONVDJDEND-LOADDATACAPTUREOBJECTID.
WRITE:/ 'New Value:', ld_input.
*Conversion exit MATN1, internal->external for field MATERIAL CALL FUNCTION 'CONVERSION_EXIT_MATN1_OUTPUT' EXPORTING input = WA_PDGRKONVDJDEND-MATERIAL IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_PDGRKONVDJDEND-MATERIAL.
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_PDGRKONVDJDEND_STR,
MANDT TYPE STRING,
PRICINGKEY TYPE STRING,
PRICINGDOCUMENTITEM TYPE STRING,
CONDITIONTYPE TYPE STRING,
SUBCONDITIONTYPE TYPE STRING,
VERSSTOCKRECORDUUID TYPE STRING,
MTMDATASOURCETYPE TYPE STRING,
SOURCETRANSACTIONEVENTDATETIME TYPE STRING,
SOURCETRANSACEVENTENDDATETIME TYPE STRING,
SOURCETRANSACTIONEVENTDATE TYPE STRING,
MATERIALBASEUNIT TYPE STRING,
COMMODITYUNIT TYPE STRING,
CMMDTYPRICEEXPSRMASSUNIT TYPE STRING,
CMMDTYPRICEEXPSRVOLUMEUNIT TYPE STRING,
COMMODITYQUANTITYINBASEUNIT TYPE STRING,
COMMODITYQUANTITY TYPE STRING,
CMMDTYPRICEEXPSRQTYINMASSUNIT TYPE STRING,
CMMDTYPRICEEXPSRQTYINVOLUNIT TYPE STRING,
COMMODITYEXPOSUREQUANTITY TYPE STRING,
COMMODITYEXPOSUREUNIT TYPE STRING,
QUANTITYSIGN TYPE STRING,
SOURCEDOCUMENT TYPE STRING,
SOURCEDOCUMENTITEM TYPE STRING,
SOURCEDOCUMENTBUSOBJTYPE TYPE STRING,
SOURCEDOCUMENTYEAR TYPE STRING,
MTMCONDITIONGROUPCATEGORY TYPE STRING,
GOODSMOVEMENTTYPE TYPE STRING,
LOADDATACAPTUREOBJECTID TYPE STRING,
LOADDATACAPTUREEVENTTYPE TYPE STRING,
QUANTITYREPOSITORYUUID TYPE STRING,
QUANTITYREPOSITORYVERSION TYPE STRING,
NETPRICEEXPSRQTYINBASEUNIT TYPE STRING,
NETPRICEEXPSRQUANTITY TYPE STRING,
NETPRICEEXPSRQTYINMASSUNIT TYPE STRING,
NETPRICEEXPSRQTYINVOLUMEUNIT TYPE STRING,
NETEXPOSUREQUANTITY TYPE STRING,
DISCPREMQTYSCHEDULEUNIQUEID TYPE STRING,
DISCPREMQTYSCHEDULEVERSION TYPE STRING,
RECORDISLOGICALLYDELETED TYPE STRING,
NETDRYERRORCODE TYPE STRING,
DISCPREMQTYSCHEDULETYPE TYPE STRING,
DAILYGRAINREPORTDISPLAYUNIT TYPE STRING,
DAILYGRAINREPORTTYPE TYPE STRING,
DAILYGRAINREPORTDATE TYPE STRING,
PLANT TYPE STRING,
MATERIAL TYPE STRING,
STORAGELOCATION TYPE STRING,
COMMODITY TYPE STRING,
PHYSICALCOMMODITY TYPE STRING,
COMPANYCODE TYPE STRING,
ENDOFDAYBUSINESSENTITYKEY TYPE STRING,
QUOTATIONKEYTYPE TYPE STRING,
MTMCALCULATIONGROUP TYPE STRING,
PLANTGROUP TYPE STRING,
ENDOFDAYTIMESTAMP TYPE STRING,
PREVIOUSENDOFDAYTIMESTAMP TYPE STRING,
BEGINGINGBOOKBALANCETTIMESTAMP TYPE STRING,
MESSAGETEXT TYPE STRING,
DENDEVALUATIONKEYDATE TYPE STRING,
DENDENDOFDAYSNAPSHOTDATETIME TYPE STRING,END OF T_EKKO_STR. DATA: WA_PDGRKONVDJDEND_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_PDGRKONVDJDEND_STR-MANDT sy-vline
WA_PDGRKONVDJDEND_STR-PRICINGKEY sy-vline
WA_PDGRKONVDJDEND_STR-PRICINGDOCUMENTITEM sy-vline
WA_PDGRKONVDJDEND_STR-CONDITIONTYPE sy-vline
WA_PDGRKONVDJDEND_STR-SUBCONDITIONTYPE sy-vline
WA_PDGRKONVDJDEND_STR-VERSSTOCKRECORDUUID sy-vline
WA_PDGRKONVDJDEND_STR-MTMDATASOURCETYPE sy-vline
WA_PDGRKONVDJDEND_STR-SOURCETRANSACTIONEVENTDATETIME sy-vline
WA_PDGRKONVDJDEND_STR-SOURCETRANSACEVENTENDDATETIME sy-vline
WA_PDGRKONVDJDEND_STR-SOURCETRANSACTIONEVENTDATE sy-vline
WA_PDGRKONVDJDEND_STR-MATERIALBASEUNIT sy-vline
WA_PDGRKONVDJDEND_STR-COMMODITYUNIT sy-vline
WA_PDGRKONVDJDEND_STR-CMMDTYPRICEEXPSRMASSUNIT sy-vline
WA_PDGRKONVDJDEND_STR-CMMDTYPRICEEXPSRVOLUMEUNIT sy-vline
WA_PDGRKONVDJDEND_STR-COMMODITYQUANTITYINBASEUNIT sy-vline
WA_PDGRKONVDJDEND_STR-COMMODITYQUANTITY sy-vline
WA_PDGRKONVDJDEND_STR-CMMDTYPRICEEXPSRQTYINMASSUNIT sy-vline
WA_PDGRKONVDJDEND_STR-CMMDTYPRICEEXPSRQTYINVOLUNIT sy-vline
WA_PDGRKONVDJDEND_STR-COMMODITYEXPOSUREQUANTITY sy-vline
WA_PDGRKONVDJDEND_STR-COMMODITYEXPOSUREUNIT sy-vline
WA_PDGRKONVDJDEND_STR-QUANTITYSIGN sy-vline
WA_PDGRKONVDJDEND_STR-SOURCEDOCUMENT sy-vline
WA_PDGRKONVDJDEND_STR-SOURCEDOCUMENTITEM sy-vline
WA_PDGRKONVDJDEND_STR-SOURCEDOCUMENTBUSOBJTYPE sy-vline
WA_PDGRKONVDJDEND_STR-SOURCEDOCUMENTYEAR sy-vline
WA_PDGRKONVDJDEND_STR-MTMCONDITIONGROUPCATEGORY sy-vline
WA_PDGRKONVDJDEND_STR-GOODSMOVEMENTTYPE sy-vline
WA_PDGRKONVDJDEND_STR-LOADDATACAPTUREOBJECTID sy-vline
WA_PDGRKONVDJDEND_STR-LOADDATACAPTUREEVENTTYPE sy-vline
WA_PDGRKONVDJDEND_STR-QUANTITYREPOSITORYUUID sy-vline
WA_PDGRKONVDJDEND_STR-QUANTITYREPOSITORYVERSION sy-vline
WA_PDGRKONVDJDEND_STR-NETPRICEEXPSRQTYINBASEUNIT sy-vline
WA_PDGRKONVDJDEND_STR-NETPRICEEXPSRQUANTITY sy-vline
WA_PDGRKONVDJDEND_STR-NETPRICEEXPSRQTYINMASSUNIT sy-vline
WA_PDGRKONVDJDEND_STR-NETPRICEEXPSRQTYINVOLUMEUNIT sy-vline
WA_PDGRKONVDJDEND_STR-NETEXPOSUREQUANTITY sy-vline
WA_PDGRKONVDJDEND_STR-DISCPREMQTYSCHEDULEUNIQUEID sy-vline
WA_PDGRKONVDJDEND_STR-DISCPREMQTYSCHEDULEVERSION sy-vline
WA_PDGRKONVDJDEND_STR-RECORDISLOGICALLYDELETED sy-vline
WA_PDGRKONVDJDEND_STR-NETDRYERRORCODE sy-vline
WA_PDGRKONVDJDEND_STR-DISCPREMQTYSCHEDULETYPE sy-vline
WA_PDGRKONVDJDEND_STR-DAILYGRAINREPORTDISPLAYUNIT sy-vline
WA_PDGRKONVDJDEND_STR-DAILYGRAINREPORTTYPE sy-vline
WA_PDGRKONVDJDEND_STR-DAILYGRAINREPORTDATE sy-vline
WA_PDGRKONVDJDEND_STR-PLANT sy-vline
WA_PDGRKONVDJDEND_STR-MATERIAL sy-vline
WA_PDGRKONVDJDEND_STR-STORAGELOCATION sy-vline
WA_PDGRKONVDJDEND_STR-COMMODITY sy-vline
WA_PDGRKONVDJDEND_STR-PHYSICALCOMMODITY sy-vline
WA_PDGRKONVDJDEND_STR-COMPANYCODE sy-vline
WA_PDGRKONVDJDEND_STR-ENDOFDAYBUSINESSENTITYKEY sy-vline
WA_PDGRKONVDJDEND_STR-QUOTATIONKEYTYPE sy-vline
WA_PDGRKONVDJDEND_STR-MTMCALCULATIONGROUP sy-vline
WA_PDGRKONVDJDEND_STR-PLANTGROUP sy-vline
WA_PDGRKONVDJDEND_STR-ENDOFDAYTIMESTAMP sy-vline
WA_PDGRKONVDJDEND_STR-PREVIOUSENDOFDAYTIMESTAMP sy-vline
WA_PDGRKONVDJDEND_STR-BEGINGINGBOOKBALANCETTIMESTAMP sy-vline
WA_PDGRKONVDJDEND_STR-MESSAGETEXT sy-vline
WA_PDGRKONVDJDEND_STR-DENDEVALUATIONKEYDATE sy-vline
WA_PDGRKONVDJDEND_STR-DENDENDOFDAYSNAPSHOTDATETIME sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.