ABAP Select data from SAP table CDOCLPRDETAILS 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 CDOCLPRDETAILS 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 CDOCLPRDETAILS. 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 CDOCLPRDETAILS 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_CDOCLPRDETAILS TYPE STANDARD TABLE OF CDOCLPRDETAILS, WA_CDOCLPRDETAILS TYPE CDOCLPRDETAILS, 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: <CDOCLPRDETAILS> TYPE CDOCLPRDETAILS. *Process all fields in table header/work area as string values PERFORM process_as_string_field_values CHANGING wa_CDOCLPRDETAILS. SELECT * *restrict ABAP select to first 10 rows UP TO 10 ROWS FROM CDOCLPRDETAILS INTO TABLE IT_CDOCLPRDETAILS. *Select data and declare internal table using in-line method @DATA *SELECT * * FROM CDOCLPRDETAILS * INTO TABLE @DATA(IT_CDOCLPRDETAILS2). *--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_CDOCLPRDETAILS INDEX 1 INTO DATA(WA_CDOCLPRDETAILS2). *Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL LOOP AT IT_CDOCLPRDETAILS ASSIGNING <CDOCLPRDETAILS>.*To update a field value using a field symbol simply change the value via the field symbol pointer
<CDOCLPRDETAILS>-MANDT = 1.
<CDOCLPRDETAILS>-PURCHASEREQUISITION = 1.
<CDOCLPRDETAILS>-PURCHASEREQUISITIONITEM = 1.
<CDOCLPRDETAILS>-PURCHASEREQNACCTASSGMTNUMBER = 1.
<CDOCLPRDETAILS>-PURCHASINGDOCUMENTTYPE = 1.
ENDLOOP. LOOP AT IT_CDOCLPRDETAILS INTO WA_CDOCLPRDETAILS. *Write horizonal line to screen report. WRITE:/ sy-uline. *Write selected data to screen/report before conversion. WRITE:/ sy-vline, WA_CDOCLPRDETAILS-PURCHASINGDOCUMENTCATEGORY, sy-vline,
WA_CDOCLPRDETAILS-PROCESSINGSTATUS, sy-vline,
WA_CDOCLPRDETAILS-PURCHASEREQUISITIONSTATUS, sy-vline,
WA_CDOCLPRDETAILS-ISDELETED, sy-vline,
WA_CDOCLPRDETAILS-PURCHASEORDERITEMCATEGORY, sy-vline,
WA_CDOCLPRDETAILS-ACCTASSIGNMENTCATEGORY, sy-vline.
ENDLOOP. *Add any further fields from structure WA_CDOCLPRDETAILS 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_CDOCLPRDETAILS 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_CDOCLPRDETAILS INTO WA_CDOCLPRDETAILS. *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 PURCHASEREQUISITION CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_CDOCLPRDETAILS-PURCHASEREQUISITION IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_CDOCLPRDETAILS-PURCHASEREQUISITION.
WRITE:/ 'New Value:', ld_input.
*Conversion exit MATN1, internal->external for field MATERIAL CALL FUNCTION 'CONVERSION_EXIT_MATN1_OUTPUT' EXPORTING input = WA_CDOCLPRDETAILS-MATERIAL IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_CDOCLPRDETAILS-MATERIAL.
WRITE:/ 'New Value:', ld_input.
*Conversion exit MATN1, internal->external for field MANUFACTURERMATERIAL CALL FUNCTION 'CONVERSION_EXIT_MATN1_OUTPUT' EXPORTING input = WA_CDOCLPRDETAILS-MANUFACTURERMATERIAL IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_CDOCLPRDETAILS-MANUFACTURERMATERIAL.
WRITE:/ 'New Value:', ld_input.
*Conversion exit CUNIT, internal->external for field MATERIALBASEUNIT CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_CDOCLPRDETAILS-MATERIALBASEUNIT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_CDOCLPRDETAILS-MATERIALBASEUNIT.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field SUPPLIER CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_CDOCLPRDETAILS-SUPPLIER IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_CDOCLPRDETAILS-SUPPLIER.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field FIXEDSUPPLIER CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_CDOCLPRDETAILS-FIXEDSUPPLIER IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_CDOCLPRDETAILS-FIXEDSUPPLIER.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field PURCHASINGINFORECORD CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_CDOCLPRDETAILS-PURCHASINGINFORECORD IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_CDOCLPRDETAILS-PURCHASINGINFORECORD.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field COSTCENTER CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_CDOCLPRDETAILS-COSTCENTER IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_CDOCLPRDETAILS-COSTCENTER.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field PRODUCTIONORDER CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_CDOCLPRDETAILS-PRODUCTIONORDER IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_CDOCLPRDETAILS-PRODUCTIONORDER.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field PURCHASINGDOCUMENT CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_CDOCLPRDETAILS-PURCHASINGDOCUMENT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_CDOCLPRDETAILS-PURCHASINGDOCUMENT.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ABPSP, internal->external for field WBSELEMENTINTERNALID CALL FUNCTION 'CONVERSION_EXIT_ABPSP_OUTPUT' EXPORTING input = WA_CDOCLPRDETAILS-WBSELEMENTINTERNALID IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_CDOCLPRDETAILS-WBSELEMENTINTERNALID.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ABPSN, internal->external for field WBSELEMENTEXTERNALID CALL FUNCTION 'CONVERSION_EXIT_ABPSN_OUTPUT' EXPORTING input = WA_CDOCLPRDETAILS-WBSELEMENTEXTERNALID IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_CDOCLPRDETAILS-WBSELEMENTEXTERNALID.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field SALESORDER CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_CDOCLPRDETAILS-SALESORDER IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_CDOCLPRDETAILS-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_CDOCLPRDETAILS_STR,
MANDT TYPE STRING,
PURCHASEREQUISITION TYPE STRING,
PURCHASEREQUISITIONITEM TYPE STRING,
PURCHASEREQNACCTASSGMTNUMBER TYPE STRING,
PURCHASINGDOCUMENTTYPE TYPE STRING,
PURCHASINGDOCUMENTCATEGORY TYPE STRING,
PROCESSINGSTATUS TYPE STRING,
PURCHASEREQUISITIONSTATUS TYPE STRING,
ISDELETED TYPE STRING,
PURCHASEORDERITEMCATEGORY TYPE STRING,
ACCTASSIGNMENTCATEGORY TYPE STRING,
MATERIAL TYPE STRING,
MANUFACTURERMATERIAL TYPE STRING,
PURCHASEREQUISITIONITEMTEXT TYPE STRING,
QUANTITY TYPE STRING,
MATERIALBASEUNIT TYPE STRING,
PURREQCREATIONDATE TYPE STRING,
MATERIALGROUP TYPE STRING,
PLANT TYPE STRING,
PURCHASINGGROUP TYPE STRING,
REQUISITIONERUSER TYPE STRING,
SUPPLIER TYPE STRING,
FIXEDSUPPLIER TYPE STRING,
SUPPLIERADDRESSCOUNTRY TYPE STRING,
SUPPLIERADDRESSCITY TYPE STRING,
SUPPLYINGPLANT TYPE STRING,
SUPPLYINGPLANTNAME TYPE STRING,
PURCHASINGORGANIZATION TYPE STRING,
PURCHASINGINFORECORD TYPE STRING,
COSTCENTER TYPE STRING,
COSTCENTERNAME TYPE STRING,
CONTROLLINGAREA TYPE STRING,
PRODUCTIONORDER TYPE STRING,
DELIVERYDATE TYPE STRING,
MATERIALCOMPONENTPRICE TYPE STRING,
MATERIALPRICEUNITQTY TYPE STRING,
CREATEDBYUSER TYPE STRING,
PURGDOCTRANSACTIONCURRENCY TYPE STRING,
PURCHASINGDOCUMENT TYPE STRING,
PURCHASINGDOCUMENTITEM TYPE STRING,
ORDEREDQUANTITY TYPE STRING,
SUPPLIERNAME TYPE STRING,
VENDORSEARCHTEXT TYPE STRING,
PURCHASINGGROUPNAME TYPE STRING,
PURCHASINGORGANIZATIONNAME TYPE STRING,
PLANTNAME TYPE STRING,
SERVICEPERFORMER TYPE STRING,
SERVICEPERFORMERNAME TYPE STRING,
WORKITEM TYPE STRING,
CNTB TYPE STRING,
WBSELEMENTINTERNALID TYPE STRING,
WBSELEMENTEXTERNALID TYPE STRING,
WORKPACKAGEFULLNAME TYPE STRING,
SALESORDER TYPE STRING,
STATUS TYPE STRING,
VENDOR TYPE STRING,
VENDORNAME TYPE STRING,
ISENDOFPURPOSEBLOCKED TYPE STRING,END OF T_EKKO_STR. DATA: WA_CDOCLPRDETAILS_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_CDOCLPRDETAILS_STR-MANDT sy-vline
WA_CDOCLPRDETAILS_STR-PURCHASEREQUISITION sy-vline
WA_CDOCLPRDETAILS_STR-PURCHASEREQUISITIONITEM sy-vline
WA_CDOCLPRDETAILS_STR-PURCHASEREQNACCTASSGMTNUMBER sy-vline
WA_CDOCLPRDETAILS_STR-PURCHASINGDOCUMENTTYPE sy-vline
WA_CDOCLPRDETAILS_STR-PURCHASINGDOCUMENTCATEGORY sy-vline
WA_CDOCLPRDETAILS_STR-PROCESSINGSTATUS sy-vline
WA_CDOCLPRDETAILS_STR-PURCHASEREQUISITIONSTATUS sy-vline
WA_CDOCLPRDETAILS_STR-ISDELETED sy-vline
WA_CDOCLPRDETAILS_STR-PURCHASEORDERITEMCATEGORY sy-vline
WA_CDOCLPRDETAILS_STR-ACCTASSIGNMENTCATEGORY sy-vline
WA_CDOCLPRDETAILS_STR-MATERIAL sy-vline
WA_CDOCLPRDETAILS_STR-MANUFACTURERMATERIAL sy-vline
WA_CDOCLPRDETAILS_STR-PURCHASEREQUISITIONITEMTEXT sy-vline
WA_CDOCLPRDETAILS_STR-QUANTITY sy-vline
WA_CDOCLPRDETAILS_STR-MATERIALBASEUNIT sy-vline
WA_CDOCLPRDETAILS_STR-PURREQCREATIONDATE sy-vline
WA_CDOCLPRDETAILS_STR-MATERIALGROUP sy-vline
WA_CDOCLPRDETAILS_STR-PLANT sy-vline
WA_CDOCLPRDETAILS_STR-PURCHASINGGROUP sy-vline
WA_CDOCLPRDETAILS_STR-REQUISITIONERUSER sy-vline
WA_CDOCLPRDETAILS_STR-SUPPLIER sy-vline
WA_CDOCLPRDETAILS_STR-FIXEDSUPPLIER sy-vline
WA_CDOCLPRDETAILS_STR-SUPPLIERADDRESSCOUNTRY sy-vline
WA_CDOCLPRDETAILS_STR-SUPPLIERADDRESSCITY sy-vline
WA_CDOCLPRDETAILS_STR-SUPPLYINGPLANT sy-vline
WA_CDOCLPRDETAILS_STR-SUPPLYINGPLANTNAME sy-vline
WA_CDOCLPRDETAILS_STR-PURCHASINGORGANIZATION sy-vline
WA_CDOCLPRDETAILS_STR-PURCHASINGINFORECORD sy-vline
WA_CDOCLPRDETAILS_STR-COSTCENTER sy-vline
WA_CDOCLPRDETAILS_STR-COSTCENTERNAME sy-vline
WA_CDOCLPRDETAILS_STR-CONTROLLINGAREA sy-vline
WA_CDOCLPRDETAILS_STR-PRODUCTIONORDER sy-vline
WA_CDOCLPRDETAILS_STR-DELIVERYDATE sy-vline
WA_CDOCLPRDETAILS_STR-MATERIALCOMPONENTPRICE sy-vline
WA_CDOCLPRDETAILS_STR-MATERIALPRICEUNITQTY sy-vline
WA_CDOCLPRDETAILS_STR-CREATEDBYUSER sy-vline
WA_CDOCLPRDETAILS_STR-PURGDOCTRANSACTIONCURRENCY sy-vline
WA_CDOCLPRDETAILS_STR-PURCHASINGDOCUMENT sy-vline
WA_CDOCLPRDETAILS_STR-PURCHASINGDOCUMENTITEM sy-vline
WA_CDOCLPRDETAILS_STR-ORDEREDQUANTITY sy-vline
WA_CDOCLPRDETAILS_STR-SUPPLIERNAME sy-vline
WA_CDOCLPRDETAILS_STR-VENDORSEARCHTEXT sy-vline
WA_CDOCLPRDETAILS_STR-PURCHASINGGROUPNAME sy-vline
WA_CDOCLPRDETAILS_STR-PURCHASINGORGANIZATIONNAME sy-vline
WA_CDOCLPRDETAILS_STR-PLANTNAME sy-vline
WA_CDOCLPRDETAILS_STR-SERVICEPERFORMER sy-vline
WA_CDOCLPRDETAILS_STR-SERVICEPERFORMERNAME sy-vline
WA_CDOCLPRDETAILS_STR-WORKITEM sy-vline
WA_CDOCLPRDETAILS_STR-CNTB sy-vline
WA_CDOCLPRDETAILS_STR-WBSELEMENTINTERNALID sy-vline
WA_CDOCLPRDETAILS_STR-WBSELEMENTEXTERNALID sy-vline
WA_CDOCLPRDETAILS_STR-WORKPACKAGEFULLNAME sy-vline
WA_CDOCLPRDETAILS_STR-SALESORDER sy-vline
WA_CDOCLPRDETAILS_STR-STATUS sy-vline
WA_CDOCLPRDETAILS_STR-VENDOR sy-vline
WA_CDOCLPRDETAILS_STR-VENDORNAME sy-vline
WA_CDOCLPRDETAILS_STR-ISENDOFPURPOSEBLOCKED sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.