Skip to Content
0
Jan 18, 2020 at 12:01 AM

BAPI_DOCUMENT_CREATE2 Longtext N lines problem

165 Views Last edit Jan 18, 2020 at 12:03 AM 2 rev

Hi.

I'm using this BAPI_DOCUMENT_CREATE2 to create a CV01N document, when the user choose a PDF file to upload and put a text to justify its necessity.

The user can fill two or more lines.

But when I execute it filling 2 or 3 lines, the longtext has just one line in the created document when I enter CV03N to see it.

Follow an attached CV03N document showing only one line on description tab. :/

FORM upload_anexo CHANGING p_documentnumber TYPE bapi_doc_aux-docnumber.


 DATA:
  "BAPI_DOCUMENT_CREATE2
 ls_documentdata LIKE bapi_doc_draw2,
 lt_documentfiles TYPE STANDARD TABLE OF bapi_doc_files2,
 ls_documentfiles LIKE LINE OF lt_documentfiles,
 lt_longtexts TYPE STANDARD TABLE OF bapi_doc_text,
 ls_longtexts LIKE LINE OF lt_longtexts,
 lv_documentnumber TYPE bapi_doc_aux-docnumber, 
 ls_return TYPE bapiret2.


 CLEAR p_documentnumber.


*--------------------------------------------------------------------*
 " obligate user to fill text to justify the bill.
*--------------------------------------------------------------------*
 CALL SCREEN 200.


 " Read user text writen on 0200 screen (editor box)
 " back from screen 0200
 IF g_mytable[] IS NOT INITIAL.
 FREE lt_longtexts.


 LOOP AT g_mytable INTO DATA(ls_mytable).
   CLEAR ls_longtexts.
*  ls_longtexts-deletevalue
   ls_longtexts-language = 'P'."sy-langu.
   ls_longtexts-language_iso = 'PT'."sy-langu.
   ls_longtexts-textline = ls_mytable-line.
   INSERT ls_longtexts INTO TABLE lt_longtexts.
 ENDLOOP.

 ELSE.
   MESSAGE s000(zsd) WITH 'Error, user did not fill text'
                     DISPLAY LIKE 'E'.
   RETURN.
 ENDIF.


*--------------------------------------------------------------------*
 " GET FILENAME
*--------------------------------------------------------------------*
 PERFORM ler_arquivo_comprovante.


 " READ filename
 READ TABLE ti_file INTO DATA(ls_file) INDEX 1.
 IF sy-subrc = 0.
   ls_documentfiles-documenttype = 'ZAV'."Generate unic name on the system 16 characteres

  TRY.
   ls_documentfiles-documentnumber = cl_system_uuid=>create_uuid_x16_static( ).

  CATCH cx_uuid_error. "
    MESSAGE s000(zsd) WITH 'Error'
    DISPLAY LIKE 'E'.
    RETURN.
  ENDTRY.


   ls_documentfiles-documentpart = '000'.
   ls_documentfiles-documentversion = '00'.
   ls_documentfiles-storagecategory = 'DMS_C1_ST'.
   ls_documentfiles-wsapplication = 'PDF'.
   ls_documentfiles-docfile = ls_file-filename.
   ls_documentfiles-description = 'Bill example'.
   ls_documentfiles-language = 'PT'.
   INSERT ls_documentfiles INTO TABLE lt_documentfiles.
 ENDIF.


 BREAK-POINT.
*--------------------------------------------------------------------*
 " CREATE DOCUMENT CV01N
*--------------------------------------------------------------------*
 ls_documentdata-documenttype = 'ZAV'.
 ls_documentdata-documentnumber = ls_documentfiles-documentnumber. " CHAR16 unic code
 ls_documentdata-documentversion = '00'.
 ls_documentdata-documentpart = '000'.
 ls_documentdata-description = 'Bill example'.
 ls_documentdata-username = sy-uname.
 ls_documentdata-statusintern = 'LB'. "released
 

CALL FUNCTION 'BAPI_DOCUMENT_CREATE2'
 EXPORTING
    documentdata = ls_documentdata
*   HOSTNAME =
*   DOCBOMCHANGENUMBER =
*   DOCBOMVALIDFROM =
*   DOCBOMREVISIONLEVEL =
*   CAD_MODE = ' '
*   PF_FTP_DEST = ' '
*   PF_HTTP_DEST = ' '
*   DEFAULTCLASS = 'X'
 IMPORTING
*   DOCUMENTTYPE =
    documentnumber = lv_documentnumber
*   DOCUMENTPART =
*   DOCUMENTVERSION =
    return = ls_return
 TABLES
*   CHARACTERISTICVALUES =
*   CLASSALLOCATIONS =
*   DOCUMENTDESCRIPTIONS =
*   OBJECTLINKS =
*   DOCUMENTSTRUCTURE =
    documentfiles = lt_documentfiles
    longtexts = lt_longtexts
*   COMPONENTS =cv01n-text-just-1-line-error.png
 .


 IF lv_documentnumber IS NOT INITIAL.
   CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
   EXPORTING
      wait = 'X'.
     p_documentnumber = lv_documentnumber.
 ELSE.
    CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
    MESSAGE s000(zsd) WITH 'Error while creating doc'
                      DISPLAY LIKE 'E'.
    RETURN.
 ENDIF.


ENDFORM. " UPLOAD_ANEXO

Attachments