on 07-18-2007 11:54 AM
Hi all!.
How can I open an attachment (file) from DMS (document management services) txn: CV02N in R/3 from webdynpro abap application??.
Thanks in advance.
Ana
Ana,
I solve the problem.
I use 2 RFC's. In the first one I use a join with DRAD, DRAT and DRAW to show in me WD app what's the documents attached. fallow the code.
function yone.
*"----
-
""Interface local:
*" IMPORTING
*" VALUE(NR_CONTRATO) TYPE VBELN_VA
*" TABLES
*" TDOCANEX STRUCTURE YSWSD014
*" TRETORNO STRUCTURE BAPIRETURN
*"----
-
tables: vbap.
types: begin of s_objky,
sign type c length 1,
option type c length 2,
low type objky,
high type objky,
end of s_objky.
data: begin of it_teste occurs 0,
var1 type i,
var2 type c,
var3 type char4,
end of it_teste.
data: v_item type posnr_va,
qtdlin type i,
teste type range of drad-objky,
teste_line like line of teste.
"UNPACK preenche com ZERO a esquerda com o tamanho do campo
unpack nr_contrato to nr_contrato.
"joga o campo POSNR da tabela VBAP em v_item se o campo vbeln for igual ao nr. do contrato
select posnr
from vbap
into v_item
where vbeln = nr_contrato.
unpack v_item to v_item.
"cria uma tabela teste com os campos sign, option e low. Joga sempre I e EQ nos 2 primeiros e
"mescla nr_contrato com v_item e joga no campo low. Atualiza (APPEND a tabela teste).
teste_line-sign = 'I'.
teste_line-option = 'EQ'.
concatenate nr_contrato v_item into teste_line-low.
append teste_line to teste.
endselect.
"pega alguns campos das tabelas drad, drat e draw (a, b e c) e joga tudo (INNER JOIN) em teste.
select adoknr bdktxt cadatum cdappl
into corresponding fields of table tdocanex
from ( drad as a inner join drat as b on bdoknr = adoknr )
inner join draw as c on cdoknr = adoknr
where a~objky in teste.
"varre a tabela tdocanex, atribui o campo vbeln o nr. do contrato e
"modifica a tabela levando em conta o indice superior.
loop at tdocanex.
tdocanex-vbeln = nr_contrato.
modify tdocanex index sy-tabix.
endloop.
"pega a quantidade de linhas em tdocanex.
"se for 0, joga E e Erro nos campos type e message.
"atualiza (APPEND) a tabela tretorno.
describe table tdocanex lines qtdlin.
if qtdlin = 0.
tretorno-type = 'E'.
tretorno-message = 'Erro'.
else.
tretorno-type = 'S'.
tretorno-message = 'Sucesso'.
endif.
append tretorno.
endfunction.
The another finds the bite array of the document.
function ytwo.
*"----
-
""Interface local:
*" IMPORTING
*" VALUE(SISTEMA) TYPE DTTRG DEFAULT 'PORTAL'
*" VALUE(ARQUIVO) TYPE FILEP OPTIONAL
*" VALUE(DOKAR) TYPE DOKAR OPTIONAL
*" VALUE(DOKNR) TYPE DOKNR OPTIONAL
*" VALUE(DOKVR) TYPE DOKVR OPTIONAL
*" VALUE(DOKTL) TYPE DOKTL_D OPTIONAL
*" TABLES
*" PTX_DATA STRUCTURE DRAO OPTIONAL
*" RETORNO STRUCTURE BAPIRETURN OPTIONAL
*"----
-
data: v_dms type draw-filep,
v_caminho type draw-filep,
lf_file_size type drao-orln,
v_ip type ni_nodeaddr,
v_rows type i.
DATA: ptx_data TYPE TABLE OF drao WITH HEADER LINE.
if arquivo is initial.
select single filep
from draw
into arquivo
where dokar eq dokar and
doknr eq doknr and
dokvr eq dokvr and
doktl eq doktl.
endif.
check not arquivo is initial.
Seleciona caminho do servidor do Portal
select single serverpath
into v_dms
from tdwd
where dttrg = sistema.
check sy-subrc eq 0.
concatenate v_dms arquivo into v_caminho.
Lê código armazenado da figura
call function 'CV120_READ_FILE2TABLE'
exporting
pf_file = v_caminho
importing:
pfx_file_size = lf_file_size
tables
ptx_data = ptx_data
exceptions
read_error = 1
others = 2.
if sy-subrc <> 0.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4 into retorno-message.
endif.
Rotina para preenchimento de tabela retornada
if lf_file_size is initial.
describe table ptx_data lines v_rows.
read table ptx_data index v_rows.
lf_file_size = ptx_data-orln.
endif.
update table drao:
documentkeys, counter, appl-no, sizes
loop at ptx_data.
ptx_data-mandt = sy-mandt.
ptx_data-dokar = dokar.
ptx_data-doknr = doknr.
ptx_data-dokvr = dokvr.
ptx_data-doktl = doktl.
ptx_data-zaehl = sy-tabix.
ptx_data-orln = lf_file_size.
modify ptx_data index sy-tabix.
endloop.
Seleciona Informação mais recente do usuário no mandante
call function 'TH_USER_INFO'
exporting
client = sy-mandt
user = sy-uname
check_gui = 0
importing
addrstr = v_ip.
clear v_caminho.
concatenate '
' v_ip 'SAPTEMPIMG.JPG' into v_caminho.
Grava dados como arquivo em diretório compartilhado
call function 'CV120_WRITE_TABLE2FILE'
exporting
pf_file = v_caminho
tables
pt_data = ptx_data
exceptions
open_error = 1
others = 2.
if sy-subrc <> 0.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4 into retorno-message.
endif.
DATA: it_frontend TYPE TABLE OF dms_frontend_data WITH HEADER LINE.
*
MOVE 'PC' TO it_frontend-frontend_type.
MOVE 'DEFAULT' TO it_frontend-hostname.
MOVE 'WN32' TO it_frontend-winsys.
*
CALL FUNCTION 'CV120_START_APPLICATION'
EXPORTING
pf_dappl = 'JPG'
pf_apptp = '1'
pf_file = v_caminho
pf_check_file = 'X'
ps_frontend = it_frontend
EXCEPTIONS
error = 1
file_not_found = 2
OTHERS = 3.
*
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4 INTO retorno-message.
ENDIF.
Caso não haja nenhum erro
commit work.
wait up to 2 seconds.
if retorno-message is initial.
move 'Sucesso.' to retorno-message.
endif.
append retorno.
"---
endfunction.
in my WD app I use the UI File download toh show the document in another window.
I will send th main code.
public void carregaDocumentosAnexos( )
{
//@@begin carregaDocumentosAnexos()
wdContext.currentYone_InputElement().setNr_Contrato(wdContext.currentContratoElement().getNroDocumento());
esvaziarDocumentos();
if(wdThis.executeRFC_Yone()){
IPrivateContratoDeAluguelComp.IAnexosNode soNode = wdContext.nodeAnexos();
for (int i = 0; i < wdContext.nodeTdocanex().size(); i++) {
IPrivateContratoDeAluguelComp.IAnexosElement soElem = wdContext.createAnexosElement();
soNode.addElement(soElem);
soElem.setNroContrato(wdContext.nodeTdocanex().getTdocanexElementAt(i).getVbeln());
soElem.setNroDocumento(wdContext.nodeTdocanex().getTdocanexElementAt(i).getDoknr());
soElem.setDescricao(wdContext.nodeTdocanex().getTdocanexElementAt(i).getDktxt());
soElem.setTipoArquivo(wdContext.nodeTdocanex().getTdocanexElementAt(i).getDappl());
soElem.setData(wdContext.nodeTdocanex().getTdocanexElementAt(i).getAdatum());
soElem.setFileId(wdContext.nodeTdocanex().getTdocanexElementAt(i).getDoknr());
soElem.setFileName(wdContext.nodeTdocanex().getTdocanexElementAt(i).getDktxt());
soElem.setFileType(wdContext.nodeTdocanex().getTdocanexElementAt(i).getDappl());
String fileExtension = null;
if ("WRD".equalsIgnoreCase(soElem.getTipoArquivo())) {
resourceType = WDWebResourceType.DOC;
fileExtension = ".doc";
}else if("JPG".equalsIgnoreCase(soElem.getTipoArquivo())){
resourceType = WDWebResourceType.JPG_IMAGE;
fileExtension = ".jpg";
}else if("PDF".equalsIgnoreCase(soElem.getTipoArquivo())){
resourceType = WDWebResourceType.PDF;
fileExtension = ".pdf";
}else if("GIF".equalsIgnoreCase(soElem.getTipoArquivo())){
resourceType = WDWebResourceType.GIF_IMAGE;
fileExtension = ".gif";
}else {
resourceType = WDWebResourceType.XLS;
fileExtension = ".xls";
}
soElem.setDwldImgOnDemResource(this.create0ByteResource(soElem, calcAttrName, "documento"+fileExtension, resourceType));
}
}
public com.sap.tc.webdynpro.progmodel.api.IWDInputStream getAnexosDwldImgOnDemStreamCalc(IPrivateContratoDeAluguelComp.IAnexosElement element)
{
//@@begin getAnexosDwldImgOnDemStreamCalc(IPrivateContratoDeAluguelComp.IAnexosElement)
IWDInputStream onDemandStream = null;
onDemandStream = WDResourceFactory.createInputStream(carregaImagem(element.getFileId()));
return onDemandStream;
//@@end
}
//@@begin others
final String CRIAR_CONTRATO = "1";
final String CONVERTER_CONTRATO = "2";
final String MODIFICAR_CONTRATO = "3";
final String VISUALIZAR_CONTRATO = "4";
final String SUBSTITUIR_CONTRATO = "5";
final String SUBSTITUIR_PASSO2 = "5b";
final String FECHAR_CONTRATO = "6";
final String CONTRATO = "YCON";
boolean validaDiarias = false;
String ITEMDOGRUPO = "";
BigDecimal VALORTARIFAACORDO = BigDecimal.valueOf(Integer.parseInt("0"));
IUser sapUser = null;
String roleName = null;
private byte[] imageData;
private String calcAttrName =
IPrivateContratoDeAluguelComp.IAnexosElement.DWLD_IMG_ON_DEM_STREAM_CALC;
private IPrivateContratoDeAluguelComp.IAnexosNode resourceNode;
private IPrivateContratoDeAluguelComp.IAnexosElement resourceElement;
private WDWebResourceType resourceType;
/**
Appends two bytes array into one.
append src to end of dest array
*/
private static byte[] byteArrayAppend(byte[] src, byte[] dest) {
byte[] z = new byte[src.length + dest.length];
int pos = 0;
if (dest.length == 0) {
pos = 0;
} else {
pos = dest.length;
}
System.arraycopy(dest, 0, z, 0, dest.length);
System.arraycopy(src, 0, z, pos, src.length);
return z;
}
private IWDResource create0ByteResource( IWDNodeElement dataNodeElement, String calcAttrName, String resourceName, WDWebResourceType resourceType) {
return WDResourceFactory.createResource(
dataNodeElement.getAttributePointer(calcAttrName),
resourceName,
resourceType);
}
private byte[] carregaImagem(String nroDocumento) {
imageData = new byte[0];
if (executeRFC_Ytwo(nroDocumento)) {
IPrivateContratoDeAluguelComp.IPtx_DataNode ptx_DataNode =
wdContext.nodePtx_Data();
for (int i = 0; i < ptx_DataNode.size(); i++) {
IPrivateContratoDeAluguelComp.IPtx_DataElement Ptx_DataElement =
ptx_DataNode.getPtx_DataElementAt(i);
// get the image data from SAP
byte[] imgData = new byte[Ptx_DataElement.getOrblk().length];
imgData = Ptx_DataElement.getOrblk();
imageData = byteArrayAppend(imgData, imageData);
}
}
return imageData;
}
//@@end
}
If you have any doubt pls write me!
Best regards.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ana,
I'm facing the same problem... I'm wondering create a RFC with the function CV120_READ_FILE2TABLE to get a bitecode to render it in some container.
But I'm working on it...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
98 | |
11 | |
11 | |
10 | |
10 | |
8 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.